/*
     raw os - Copyright (C)  Lingjun Chen(jorya_txj).

    This file is part of raw os.

    raw os is free software; you can redistribute it it under the terms of the 
    GNU General Public License as published by the Free Software Foundation; 
    either version 3 of the License, or  (at your option) any later version.

    raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program. if not, write email to jorya.txj@gmail.com
                                      ---

    A special exception to the LGPL can be applied should you wish to distribute
    a combined work that includes raw os, without being obliged to provide
    the source code for any proprietary components. See the file exception.txt
    for full details of how and when the exception can be applied.
*/


/* 	2012-9  Created by dezhi jiang
  *	xxxxxx   please added here
  */


#include "def.h"
#include "option.h"
#include "2440addr.h"     
#include "2440lib.h"
#include "2440slib.h"     
#include "mmu.h" 
#include "timer.h"

#include "raw_api.h"
#include <mm/raw_page.h>
#include <mm/raw_malloc.h>

#undef U32

#include "gui.h"
#include "FRAMEWIN.h"
#include "GUI_X.h"
#include "lcd_touch.h" 
#define  TEST_TASK_STK_SIZE 4048


RAW_TIMER timer_touch_1;

PORT_STACK gui_demo_stack1[TEST_TASK_STK_SIZE];

PORT_STACK gui_demo_stack2[TEST_TASK_STK_SIZE];

RAW_TASK_OBJ 		gui_demo_obj[2];

extern RAW_U8 test_started;

extern void GUIDEMO_main(void);
extern void Touch_init(void);
extern void Timer0Init(void);
void timer_touch_fun_1(RAW_VOID *para)
{
	GUI_TOUCH_Exec();
}

void gui_demo1(void * pParam) 
{
	RAW_U8 a = 0x55;
	Timer0Init();
	Touch_init();
	raw_timer_create(&timer_touch_1, (RAW_U8  *)"timer_touch_1",timer_touch_fun_1, &a, RAW_TICKS_PER_SECOND/100,RAW_TICKS_PER_SECOND/100,1);
//	raw_timer_activate(&timer_touch_1);

	while(1)
	{
		GUIDEMO_main();
	}
}

void gui_demo2(void * pParam) 
{
  while(1) {
    GUI_Exec();           /* Do the background work ... Update windows etc.) */
    GUI_X_ExecIdle();     /* Nothing left to do for the moment ... Idle processing */
  }
}



void gui_demo(void)
{

	if (test_started) {

		return;

	}

	test_started = 1;

	GUI_Init();
	raw_task_create(&gui_demo_obj[0], (RAW_U8  *)"gui_demo_1", 0,
	                         30, 0,  gui_demo_stack1, 
	                         TEST_TASK_STK_SIZE , gui_demo1, 1); 

	raw_task_create(&gui_demo_obj[1], (RAW_U8  *)"gui3", 0,
	                         40, 0,  gui_demo_stack2, 
	                         TEST_TASK_STK_SIZE , gui_demo2, 1);

}


